package com.reesechou.service.imp;

import com.reesechou.dao.CategoryArticleDao;
import com.reesechou.javabean.Category;
import com.reesechou.javabean.CategoryArticle;
import com.reesechou.service.CategoryArticleService;
import com.reesechou.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 小星打屁屁 on 2015/4/1.
 * contact me ==>243709758@qq.com
 */
@Service

public class CateGoryArticleServiceImp implements CategoryArticleService {

    @Autowired
    private CategoryArticleDao categoryArticleDao ;
    @Override
    public int insert(CategoryArticle entity) {
        return 0;
    }

    @Override
    public boolean insertArray(int[] array, int articleId) {

        for(int i=0;i<array.length;i++){
            CategoryArticle entity = new CategoryArticle();
            entity.setArticleId(articleId);
            entity.setCategoryId(array[i]);
            if(categoryArticleDao.insert(entity) <=0){
                return false;
            }
        }
        return  true;

    }

    /**
     * 用来添加一组String类型的数组的分类 和 一个 文章之间的对应关系
     * @param array
     * @param articleId
     * @return
     */
    public boolean insertArray(String[] array,int articleId){
        int[] newArray = new int[array.length];
        for(int i = 0; i< array.length ;i++){
            newArray[i] = Integer.parseInt(array[i]);
        }
        return insertArray(newArray,articleId);
    }

    @Override
    public List<Integer> queryByCategoryId(int categoryId) {
        return null;
    }

    @Override
    public List<Integer> queryByArticleId(int articleId) {
        return null;
    }
}
